*****************
*** Exit Poll ***
*****************



*********************************
*** Cleaning DVs and Controls ***
*********************************

*** Confusion
recode confus (1/2 = 0) (3/4 = 1), gen(confusing)

*** Confidence
recode voteconf (1/3 = 0) (4 = 1), gen(confidence)

*** Support RCV State
recode use_rcv_state (1 = 1) (2 = 0), gen(rcvstate)

*** # Candidates Dummy
recode numcand (1/4 = 0) (5 = 1), gen(cand)

*** Age
gen age3 = .
replace age3 = 1 if agecat == 1 | agecat == 2
replace age3 = 2 if agecat == 3 | agecat == 4
replace age3 = 3 if agecat == 5 | agecat == 6

*** Party
tab party3

*** Gender 
recode gender (1 = 0) (2 = 1) (3/4 = .), gen(female)

*** Race 
gen race3 = .
replace race3 = 1 if race == 2
replace race3 = 2 if race == 1
replace race3 = 3 if race == 3 | race == 4 | race == 5 | race == 6 

gen hispanic = .
replace hispanic = 1 if race3 == 2
replace hispanic = 0 if race3 == 1 | race3 == 3

*** Education
recode educ (1/2 = 1) (3 = 2) (4 = 3), gen(educ3)

*** Voting Experience Index
recode find_park (1 = 4) (2 = 3) (3 = 2) (4  = 1), gen(rev_park)
recode find_loc (1 = 4) (2 = 3) (3 = 2) (4  = 1), gen(rev_loc)

egen eval = rowmean(rev_park rev_loc help_worker)
recode eval(1 = 1) (1.3/3 = 0), gen(good_exp)

*** Dummies for numcand 
recode numcand 1/4=0 5=1, gen(numcand5)
recode numcand 1/3=0 4=1 5=0, gen(numcand4)
recode numcand 1/2=0 3=1 4/5=0, gen(numcand3)
recode numcand 1=0 2=1 3/5=0, gen(numcand2)
recode numcand 1=1 2/5=0, gen(numcand1)

*** In sample
gen insample=1
foreach i in confusing numcand confidence RCVfuturecity rcvstate good_exp {
reg `i' i.race3 i.age3 i.party3 i.educ3 female 
replace insample=0 if e(sample)==0
}

**************
*** Labels ***
**************
label variable confusing "Confusion" 
label variable confidence "Confidence"
label variable numcand "# Candidates"
label variable numcand "# Candidates"
label define party 1 "Democrat" 2 "Independent" 3 "Republican"
label values party3 party
label define race 1 "White" 2 "Hispanic" 3 "Other"
label values race3 race
label variable female "Female"
label define age 1 "18-34" 2 "35-54" 3 "55+"
label values age3 age
label define educ 1 "Less than college" 2 "College" 3 "Postgraduate"
label values educ3 educ 
label variable cand "Ranked 5"
label define ranked 1 "Ranked 1" 2 "Ranked 2" 3 "Ranked 3" 4 "Ranked 4" 5 "Ranked 5"
label values numcand ranked

***************
*** Weights ***
***************
*gen gen_tot = .					
*replace gen_tot = 6981 if female == 1
*replace gen_tot = 5328 if female == 0
*
*gen hisp_tot = .					
*replace hisp_tot = 3853 if race3 == 2
*replace hisp_tot = 8456 if race3 == 1 | race3 == 3

*gen age_tot = .					
*replace age_tot = 928 if age3 == 1
*replace age_tot = 3627 if age3 == 2
*replace age_tot = 7754 if age3 == 3
*
*gen party_tot = .					
*replace party_tot = 9791 if party3 == 1
*replace party_tot = 1281 if party3 == 2
*replace party_tot = 1237 if party3 == 3

*gen pid_weight = 1 
*survwgt rake pid_weight if insample==1, by(female hispanic age3 party3) totvars(gen_tot hisp_tot *age_tot party_tot) modify

*** Setting weight (note that the weight is already created in the replication dataset)
svyset[pw=pid_weight]

******************************
*** Descriptive Statistics ***
******************************

svy: tab confus if insample ==1, percent
svy: tab confusing if insample ==1, percent

svy: tab numcand if insample ==1, percent
svy: mean numcand if insample ==1

svy: tab voteconf if insample ==1, percent

svy: tab RCVfuturecity if insample ==1, percent

svy: tab rcvstate if insample ==1, percent

**************
*** Models ***
**************

*** Confusion T-Tests
svy: mean confusing if insample == 1, over(race3) coeflegend 
test _b[c.confusing@1bn.race3] = _b[c.confusing@2.race3]
test _b[c.confusing@1bn.race3] = _b[c.confusing@3.race3]

*** Number of Candidates T-Tests
svy: mean numcand if insample == 1, over(race3) coeflegend 
test _b[c.numcand@1bn.race3] = _b[c.numcand@2.race3]
test _b[c.numcand@1bn.race3] = _b[c.numcand@3.race3]

svy: mean numcand if insample == 1, over(confusing) coeflegend 
test _b[c.numcand@0bn.confusing] = _b[c.numcand@1bn.confusing]

*** Confidence T-Tests
svy: mean confidence if insample == 1, over(race3) coeflegend 
test _b[c.confidence@1bn.race3] =  _b[c.confidence@2.race3]
test _b[c.confidence@1bn.race3] = _b[c.confidence@3.race3]

svy: mean confidence if insample == 1, over(confusing) coeflegend 
test _b[c.confidence@0bn.confusing] = _b[c.confidence@1bn.confusing]

svy: mean confidence if insample == 1, over(numcand) coeflegend 
test _b[c.confidence@5.numcand] = _b[c.confidence@4.numcand]
test _b[c.confidence@5.numcand] = _b[c.confidence@3.numcand]
test _b[c.confidence@5.numcand] = _b[c.confidence@2.numcand]
test _b[c.confidence@5.numcand] = _b[c.confidence@1.numcand]

*** Local RCV T-Tests
svy: mean RCVfuturecity if insample == 1, over(race3) coeflegend 
test _b[c.RCVfuturecity@1bn.race3] = _b[c.RCVfuturecity@2.race3]
test _b[c.RCVfuturecity@1bn.race3] = _b[c.RCVfuturecity@3.race3]

svy: mean RCVfuturecity if insample == 1, over(confusing) coeflegend 
test _b[c.RCVfuturecity@0bn.confusing] = _b[c.RCVfuturecity@1bn.confusing]

svy: mean RCVfuturecity if insample == 1, over(numcand) coeflegend 
test _b[c.RCVfuturecity@5.numcand] = _b[c.RCVfuturecity@4.numcand]
test _b[c.RCVfuturecity@5.numcand] = _b[c.RCVfuturecity@3.numcand]
test _b[c.RCVfuturecity@5.numcand] = _b[c.RCVfuturecity@2.numcand]
test _b[c.RCVfuturecity@5.numcand] = _b[c.RCVfuturecity@1.numcand]

svy: mean RCVfuturecity if insample == 1, over(confidence) coeflegend 
test _b[c.RCVfuturecity@0bn.confidence] = _b[c.RCVfuturecity@1bn.confidence]

*** State RCV T-Tests
svy: mean rcvstate if insample == 1, over(race3) coeflegend 
test _b[c.rcvstate@1bn.race3] = _b[c.rcvstate@2.race3]
test _b[c.rcvstate@1bn.race3] = _b[c.rcvstate@3.race3]

svy: mean rcvstate if insample == 1, over(confusing) coeflegend 
test _b[c.rcvstate@0bn.confusing] = _b[c.rcvstate@1bn.confusing]

svy: mean rcvstate if insample == 1, over(numcand) coeflegend 
test _b[c.rcvstate@5.numcand] = _b[c.rcvstate@4.numcand]
test _b[c.rcvstate@5.numcand] = _b[c.rcvstate@3.numcand]
test _b[c.rcvstate@5.numcand] = _b[c.rcvstate@2.numcand]
test _b[c.rcvstate@5.numcand] = _b[c.rcvstate@1.numcand]

svy: mean rcvstate if insample == 1, over(confidence) coeflegend 
test _b[c.rcvstate@0bn.confidence] = _b[c.rcvstate@1bn.confidence]

*** Regression
svy: logit confusing i.race3 i.age3 b3.party3 i.educ3 female if insample == 1  

svy: reg numcand confusing i.race3 i.age3 b3.party3 i.educ3 female if insample == 1 

svy: logit confidence good_exp confusing b5.numcand i.race3 i.age3 b3.party3 i.educ3 female if insample == 1 

svy: logit RCVfuturecity confusing b5.numcand confidence i.race3 i.age3 b3.party3 i.educ3 female if insample == 1   

svy: logit rcvstate confusing b5.numcand confidence i.race3 i.age3 b3.party3 i.educ3 female if insample == 1  

*** Tables (indicators for a 10% significance level were added manually for the paper)
asdoc svy: logit confusing i.race3 i.age3 b3.party3 i.educ3 female if insample == 1, label fs(12) font(Times New Roman) setstars(*@.05, **@.01, ***@.001) title(Table 2. Regression Models) cnames(Confusion) nest replace dec(3) tzok 

asdoc svy: reg numcand confusing i.race3 i.age3 b3.party3 i.educ3 female if insample == 1, label fs(12) font(Times New Roman) setstars(*@.05, **@.01, ***@.001) title(Table 2. Regression Models) nest append  dec(3) tzok 

asdoc svy: logit confidence good_exp confusing b5.numcand i.race3 i.age3 b3.party3 i.educ3 female if insample == 1, label fs(12) font(Times New Roman) setstars(*@.05, **@.01, ***@.001) title(Table 2. Regression Models) cnames(Confidence) nest append dec(3) tzok

asdoc svy: logit RCVfuturecity confusing b5.numcand confidence i.race3 i.age3 b3.party3 i.educ3 female if insample == 1, label fs(12) font(Times New Roman) setstars(*@.05, **@.01, ***@.001) title(Table 2. Regression Models) nest append dec(3) tzok 

asdoc svy: logit rcvstate confusing b5.numcand confidence i.race3 i.age3 b3.party3 i.educ3 female if insample == 1, label fs(12) font(Times New Roman) setstars(*@.05, **@.01, ***@.001) title(Table 2. Regression Models) nest append dec(3) tzok

*** Figures
graph set window fontface "Times New Roman"

svy: logit confidence good_exp confusing b5.numcand i.race3 i.age3 b3.party3 i.educ3 female if insample == 1 
margins, dydx(confusing b5.numcand 2.race3) post
coefplot, xline(0) xti(Average First Difference, size(small)) scheme(s1mono) xlab(-.4 (.1) .4, tlcolor(black) nogrid labs(small)) ylab(, tlcolor(black) nogextend labs(small))  grid(none) ciopts(recast(rcap)) xscale(lc(black)) yscale(lc(black)) 

svy: logit RCVfuturecity confusing b5.numcand confidence i.race3 i.age3 b3.party3 i.educ3 female if insample == 1   
margins, dydx(confusing b5.numcand confidence 2.race3) post
estimates store results_1
svy: logit rcvstate confusing b5.numcand confidence i.race3 i.age3 b3.party3 i.educ3 female if insample == 1  
margins, dydx(confusing b5.numcand confidence 2.race3) post
estimates store results_2
coefplot results_1 results_2, xline(0) xti(Average First Difference, size(small)) scheme(s1mono) xlab(-.4 (.1) .4, tlcolor(black) nogrid labs(small)) ylab(, tlcolor(black) nogextend labs(small))  grid(none) ciopts(recast(rcap)) xscale(lc(black)) yscale(lc(black)) legend(cols(2) position(6) order(2 "Local" 4 "State") nospan size(small) region(lcolor(white)))

****************
*** Appendix ***
**************** 

*** Demographic figure
svy: logit confusing i.race3 i.age3 b3.party3 i.educ3 female if insample == 1  
margins, dydx(*) post
coefplot, xline(0) xti(Average First Difference, size(small)) scheme(s1mono) xlab(-.4 (.1) .4, tlcolor(black) nogrid labs(small)) ylab(, tlcolor(black) nogextend labs(small))  grid(none) ciopts(recast(rcap)) xscale(lc(black)) yscale(lc(black)) 

*** Descriptive Table
su confusing confus numcand i.numcand confidence voteconf RCVfuturecity rcvstate good_exp i.party3 i.race3 i.educ3 i.age3 female if insample == 1 [aw=pid_weight]

*** Predicted candidates ranked from confusion model
svy: reg numcand confusing i.race3 i.age3 b3.party3 i.educ3 female if insample == 1 
margins, at(confusing=(0 1))

svy: reg numcand confusing i.race3 i.age3 b3.party3 i.educ3 female if insample == 1 
margins, at(race3=(1 2))

*** Alternate Specifications
asdoc ologit confus i.race3 i.age3 b3.party3 i.educ3 female if insample == 1, label fs(12) font(Times New Roman) setstars(*@.05, **@.01, ***@.001) title(Table 3. Voter Confusion, Confidence, and Number of Candidates Ranked) cnames(Confusion) nest replace dec(3) tzok

asdoc ologit voteconf good_exp confusing i.numcand i.race3 i.age3 b3.party3 i.educ3 female if insample == 1, label fs(12) font(Times New Roman) setstars(*@.05, **@.01, ***@.001) title(Table 3. Voter Confusion, Confidence, and Number of Candidates Ranked) cnames(Confidence) nest append dec(3) tzok 


